package space.sakana.edusysback.mapper;

import org.apache.ibatis.annotations.*;
import space.sakana.edusysback.entity.User;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select `id`, `code`, `grade`, `username`, `password`, `gender`, `name`, `token`, `create`, `ip`, `lrt` from user where `id`=#{id};")
    User selectUserById(int id);

    @Select("select `id`, `code`, `grade`, `username`, `password`, `gender`, `name`, `token`, `create`, `ip`, `lrt` from user;")
    List<User> selectAllUsers();

    @Select("select `id`, `code`, `grade`, `username`, `password`, `gender`, `name`, `token`, `create`, `ip`, `lrt` from user where `username`=#{username};")
    User selectUserByUsername(String username);

    @Select("select `id`, `code`, `grade`, `username`, `password`, `gender`, `name`, `token`, `create`, `ip`, `lrt` from user where `code`=#{code};")
    User selectUserByCode(long code);

    @Insert("insert into user(`code`, `grade`, `username`, `password`, `gender`, `name`) values(#{code}, #{grade}, #{username}, #{password}, #{gender}, #{name});")
    int insertUser(User user);

    @Update("update user set `code`=#{code}, `grade`=#{grade}, `username`=#{username}, `password`=#{password}, `gender`=#{gender}, `name`=#{name}, `token`=#{token}, `create`=#{create}, `ip`=#{ip}, `lrt`=#{lrt} where `id`=#{id};")
    int updateUser(User user);

    @Select("select `id`, `code`, `grade`, `username`, `password`, `gender`, `name`, `token`, `create`, `ip`, `lrt` from user where `token`=#{token};")
    User selectUserByToken(String token);

    @Delete("delete from user where `id`=#{uid};")
    int deleteUser(int uid);
}
